<%-- 
    Document   : Pager
    Created on : May 22, 2010, 7:56:18 AM
    Author     : vasi
--%>
<%@page import="java.util.*" %>

<%
int total_pages = (Integer)request.getAttribute("total_pages");
int current_page = (Integer)request.getAttribute("current_page");
if (total_pages > 1){
    out.print("<div class=\"pager\">");
    String query = "?";
    Enumeration<String> names = request.getParameterNames();
    while (names.hasMoreElements()){
        String name = names.nextElement();
        if (name.equals("page")) continue;
        query += name+"="+request.getParameter(name)+"&";
    }
    if (current_page > 1){
        out.print("<a href=\""+request.getContextPath()+(String)request.getAttribute("active_servlet_path")+query+"page=1\">First</a> ");
        out.print("<a href=\""+request.getContextPath()+(String)request.getAttribute("active_servlet_path")+query+"page="+(current_page-1)+"\">Previous</a> ");
    }
    for (int index = 1; index <= total_pages; index++){
        if (index == current_page){
            out.print(index+" ");
        } else {
            out.print("<a href=\""+request.getContextPath()+(String)request.getAttribute("active_servlet_path")+query+"page="+index+"\">"+index+"</a> ");
        }
    }
    if (current_page < total_pages){
        out.print("<a href=\""+request.getContextPath()+(String)request.getAttribute("active_servlet_path")+query+"page="+(current_page+1)+"\">Next</a> ");
        out.print("<a href=\""+request.getContextPath()+(String)request.getAttribute("active_servlet_path")+query+"page="+total_pages+"\">Last</a> ");
    }
    out.print("</div>");
}
%>